package edu.hubu.talentmanagementsystem.gen;

import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import edu.hubu.talentmanagementsystem.model.Model;

/**
 * @author moonlan
 * date 2021/3/9 下午4:32
 */
@SuppressWarnings(value = "unused")
public class ModelGen {

    public static void main(String[] args) {
        AutoGenerator autoGenerator = new AutoGenerator();
        GlobalConfig globalConfig = new GlobalConfig();
        //String projectPath = System.getProperty("user.dir");
        globalConfig.setOutputDir("/home/moonlan/桌面/");
        globalConfig.setAuthor("moonlan");
        globalConfig.setOpen(false);
        autoGenerator.setGlobalConfig(globalConfig);

        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setUrl("jdbc:mysql://localhost:3306/tel_man");
        // dataSourceConfig.setSchemaName("public");
        dataSourceConfig.setDriverName("com.mysql.cj.jdbc.Driver");
        dataSourceConfig.setUsername("root");
        dataSourceConfig.setPassword("root");
        autoGenerator.setDataSource(dataSourceConfig);

        PackageConfig packageConfig = new PackageConfig();

        //如果需要手动输入模块名
        //packageConfig.setModuleName(scanner("模块名"));
        //packageConfig.setModuleName("ssmp");
        packageConfig.setParent("edu.hubu.talentmanagementsystem");
        packageConfig.setEntity("model");
        autoGenerator.setPackageInfo(packageConfig);

        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setNaming(NamingStrategy.underline_to_camel);
        strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);
        strategyConfig.setChainModel(true);
        strategyConfig.setEntitySerialVersionUID(false);
        strategyConfig.setEntityTableFieldAnnotationEnable(true);
        autoGenerator.setStrategy(strategyConfig);

        TemplateConfig templateConfig = new TemplateConfig();
        templateConfig.setEntity("ftls/model.java");
        autoGenerator.setTemplate(templateConfig);


        autoGenerator.setTemplateEngine(new FreemarkerTemplateEngine());

        autoGenerator.execute();
    }

}
